#include <stdio.h>
#include <string.h>
// 字符串逆序
void reserve(char *s, int len)
{
    for (int i = 0; i < len / 2; i++)
    {
        char temp = s[i];
        s[i] = s[len - 1 - i];
        s[len - 1 - i] = temp;
    }
}
void reserve2(char *s, int len)
{
    int count = 0;
    for (int i = 0; i < len; i++)
    {
        if (s[i] == ' ' || s[i] == '\0')
        {
            reserve(s + i - count, count);
            // 清零统计下一个单词
            count = 0;
        }
        else
        {
            count++;
        }
    }
}

int main()
{
    char s[] = "i am form nanjing";
    reserve2(s, sizeof(s));
    printf("%s", s);
    return 0;
}
